﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using Database.Classes;


public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void GetConfiguration()
    {
        using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("Select * from Configuration", conn))
            {
                SqlDataReader rdr = cmd.ExecuteReader();
                SqlContext.Pipe.Send(rdr);
                rdr.Close();
                conn.Close();
            }
        }
    }
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void MaxNumberOfPlayers()
    {
        using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("Select MaxNumberOfPlayers from Configuration", conn))
            {
                SqlDataReader rdr = cmd.ExecuteReader();
                SqlContext.Pipe.Send(rdr);
                rdr.Close();
                conn.Close();
            }
        }
    } 
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void MaxNumberOfPlanetsPerSystem()
    {
        using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("Select MaxNumberOfPlanetsPerSystem from Configuration", conn))
            {
                SqlDataReader rdr = cmd.ExecuteReader();
                SqlContext.Pipe.Send(rdr);
                rdr.Close();
                conn.Close();
            }
        }
    }  
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void MinNumberOfPlanetsPerSystem()
    {
        using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("Select MinNumberOfPlanetsPerSystem from Configuration", conn))
            {
                SqlDataReader rdr = cmd.ExecuteReader();
                SqlContext.Pipe.Send(rdr);
                rdr.Close();
                conn.Close();
            }
        }
    }
    public static string GetConfigurationForOption(string option)
    {
        using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("Select * from Configuration", conn))
            {
                SqlDataReader rdr = cmd.ExecuteReader();
                rdr.Read();
                return rdr[option].ToString();
            }
        }
    }
    public static DateTime GetGameStart()
    {
       // return new DateTime(2008, 08, 26, 12, 00, 00);
        using (SqlConnection conn = new SqlConnection(StaticMethods.ConnectionString()))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("Select GameStart from Configuration", conn))
            {
                SqlDataReader rdr = cmd.ExecuteReader();
                rdr.Read();
                return rdr.GetDateTime(0);
            }
        }
    }
};
